package com.example.quartzdemo.memory;

import com.example.quartzdemo.Entity.QuartzBean;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author yeyangtao
 * @since 2022/6/17 11:07
 */
public class LocalCacheMap implements LocalCache {

    private static Map<String, QuartzBean> LOCAL_MAP = new ConcurrentHashMap<>();

    public static LocalCache localCache = new LocalCacheMap();

    @Override
    public boolean add(QuartzBean target) {
        LOCAL_MAP.put(target.getId(), target);
        return true;
    }

    @Override
    public QuartzBean get(String key) {
        return LOCAL_MAP.get(key);
    }

    @Override
    public boolean del(String key) {
        LOCAL_MAP.remove(key);
        return true;
    }

    @Override
    public int getCount() {
        return LOCAL_MAP.size();
    }

    @Override
    public List<QuartzBean> getAll() {
        return new ArrayList<>(LOCAL_MAP.values());
    }

    @Override
    public void observer() {

    }

}
